<?php

namespace App\Services\Project;


use App\Models\Project\ContractAttachment;
use Illuminate\Support\Facades\Auth;

class AttachmentService
{
    const TYPE_CONTRACT = '合同';

    public static function createOrUpdate($contract_id, $type, $file)
    {
        ContractAttachment::updateOrCreate(['type' => $type, 'contract_id' => $contract_id], ['file_url' => $file, 'operator_uid' => Auth::id()]);
    }

    public static function getFileByType($contract_id, $type)
    {
        $attachment = ContractAttachment::query()->where('contract_id', $contract_id)->where('type', $type)->first();
        return $attachment->file_url ?? '';
    }
}
